﻿#pragma once
#include<QNetworkAccessManager>
#include<QNetworkRequest>
#include<QString>
#include<QObject>
#include<QJsonObject>
#include<QByteArray>
#include<QEventLoop>
#include<QTimer>
#include "systeminfomation.h"

class HttpRequest : public QObject
{
   Q_OBJECT
public:
    HttpRequest();
    ~HttpRequest();

    typedef enum RequestType {
        kUnknown,
        kGaRequest,                     // 数据埋点
        kRegionRequest,                 // 区域获取
        kCloudRequest,                  // 云api
        kPrevSignRequest,               // 获取预签名
        KUploadRequest,                 // 上传文件
        kFeedbackRequest,               // 反馈文件
        kDongFangCaiFuRequest
    }RequestType;

    void getRegionInfomation();

    void getStockInfo(const QString& code);

    void setFeedbackInfo(const QString& feedbackInfo, const QString& email);

    void fillDatas(const RequestType& type, const QString& url);

public slots:
    void onSendRequestPost(const QByteArray& data);

private:
    void fillHttpRequest();
    void setUrls(RequestType type, const QString url);
    const RequestType& type() { return m_type; }

    QNetworkAccessManager* m_networkAccessManager = nullptr;
    QNetworkRequest m_request;
    QMap<RequestType, QString> m_mapUrl;
    QString m_queryUrl;
    QString m_feedbackInfo;
    quint64 m_userid;
    RequestType m_type = kUnknown;
    qint64 m_checkFileSize = -1;
    qint64 m_checkCnt = 10;     // 10: 5s
    QTimer m_timer;     // 500ms


signals:
    void signalStockInfomation(const QString& name, const QString& price);

private slots:
    void dealNetworkFinisheded(QNetworkReply *reply);
};
